#ifndef FRMDEVICEUPDATE_H
#define FRMDEVICEUPDATE_H

#include <QWidget>
#include <QTimer>
#include "frmmain.h"

namespace Ui {
class frmdeviceupdate;
}

class frmmain;

class frmdeviceupdate : public QWidget
{
    Q_OBJECT

public:
    explicit frmdeviceupdate(QWidget *parent = nullptr);
    ~frmdeviceupdate();

private slots:
    void on_enterSettingModeButton_clicked();
    void on_exitSettingModeButton_clicked();
    void on_sendConfigButton_clicked();
    void on_saveConfigButton_clicked();
    void on_loadConfigButton_clicked();
    void on_cancelButton_clicked();
    void onSerialConnectionChanged(bool connected);
    void onTcpConnectionChanged(bool connected);
    void onSerialDataReceived(const QString &data);
    void onTcpDataReceived(const QString &data);
    void onResponseTimeout();

private:
    Ui::frmdeviceupdate *ui;
    frmmain *mainWindow;
    bool isSettingMode;
    bool isWaitingForMqttConfig;
    QString lastCommand;
    QTimer responseTimer;

    void sendSettingModeCommand(bool enter);
    void updateMainResponse(const QString &msg);
    void enableConfigControls(bool enable);
    void resetConfigFields();
    void updateSettingModeButtonState();
    void sendMqttQueryCommand();
    void parseMqttConfigResponse(const QString &data);
    void startResponseTimer();
};

#endif // FRMDEVICEUPDATE_H